# coding:utf-8
from conf.config.prod_config import config
from util.commonLog import commonLog
import logging
from util.excelUtil import getRowsData
from util.requestUtil import sendRequest
from util.yamlLoader import loadYamlFile


class testMycase(object):

    def __init__(self):
        self.host = config['host']
        self.path = config['path_getuserinfo']
        self.url = self.host + self.path

        logging.setLoggerClass(commonLog)
        self.logger = logging.getLogger(__name__)

        #self.yamlData = loadYamlFile('/Users/u51/PycharmProjects/pythonproject/testData/rubyData.yml')
        #self.logger.info(self.yamlData['specialString'])
        #self.logger.info(self.yamlData['dictString']['dicta'])


    def setUp(self):
        self.logger.info("========setUp========")

    def tearDown(self):
        self.logger.info("==========tearDown==========")

    def testGetUserStatus(self):

        # 发起请求得到返回
        headers = config['get_headers']
        data = getRowsData('testData.xlsx', u'工作表1', 1)
        self.logger.info(data)
        host = data[0]
        url = data[1]
        method = data[2]
        params = data[3]
        path = host + url
        code, result = sendRequest(self,path, method, headers=headers, params=params)
        assert result['message'] == u'成功', u'result:{}, not equal to expectCode: {}'.format(result,u'成功')

    def testPostUserStatus(self):

        # 发起请求得到返回
        headers = config['post_headers']
        data = getRowsData('testData.xlsx', u'工作表1', 2)
        self.logger.info(data)
        host = data[0]
        url = data[1]
        method = data[2]
        params = data[3:]
        self.logger.info(str(params[0]))
        data = {
            "userId": params[0],
            "info": params[1]
        }

        path = host + url
        code, result = sendRequest(self,path, method, headers=headers, params=data)
        assert result['message'] == u'成功', u'result:{}, not equal to expectCode: {}'.format(result,u'成功')















